$(function () {
    $("body").on('click','#orderNoBath',function () {
        getOrderData(1);
    }).on('change','#payType',function () {
        getOrderData(1);
    }).on('change','#orderStatus',function () {
        getOrderData(1);
    }).on('change','#shopType',function () {
        getOrderData(1);
    }).on('click','.cancel-order',function () {//取消订单
        var _this = $(this);
        var orderId = _this.data('id');
        icModale(2, '提示', '确认取消该订单？', null, null,function (index) {
            $.ajax({
                url:baseloaction+'/web/uc/order/cancelOrder',
                type:'post',
                dataType:'json',
                data:{
                    'orderId':orderId
                },
                success:function (result) {
                    if(result.success==true){
                        _this.prev().remove();
                        _this.remove();
                        $("#order-pay-btn-"+orderId).remove();
                        $("#order-status-text-"+orderId).html('<span class="c-666">已取消</span>');
                        layer.close(index);
                    }else{
                        icModale(0,'',result.message);
                    }
                },
                error:function () {
                    icModale(0,'','系统错误，订单取消失败');
                }
            });
        });
    }).on('click','.delete-order-box',function () {//删除订单
        var _this = $(this);
        var orderId = _this.data('id');
        icModale(2, '提示', '确认删除该订单？', null, null,function (index) {
            $.ajax({
                url:baseloaction+'/web/uc/order/deleteOrder',
                type:'post',
                dataType:'json',
                data:{
                    'orderId':orderId
                },
                success:function (result) {
                    if(result.success==true){
                        _this.parents('table').remove();
                        layer.close(index);
                    }else{
                        icModale(0,'',result.message);
                    }
                },
                error:function () {
                    icModale(0,'','系统错误，订单删除失败');
                }
            });
        });
    });
    getOrderData(1);
    /**
     * 加载订单数据
     * @param pageNo 页码
     */
    function getOrderData(pageNo) {
        var params = $("#order-form-box").serializeJSON();
        params = JSON.stringify(params);
        getPageAjaxData({
            url: baseloaction + '/web/uc/order/ajaxOrderList',//请求URL
            contextId:'user-order-list-box',//响应内容页面设置内容ID
            params:params,//请求参数
            pageNo:pageNo,//页码
            pageCall:getOrderData, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            callback:function () {//数据加载完成回调
                lazyCourseImage();
            }
        });
    }
});